<%--
  Author: DawnFz.com
  Date: 2022/9/14 21:01
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="ctxPath" value="${pageContext.request.contextPath}"/>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${ctxPath}/static/layui/css/layui.css"/>
    <title>审批流程</title>
    <script src="${ctxPath}/static/layui/layui.js"></script>
    <script src="${ctxPath}/static/js/jquery-3.6.1.min.js"></script>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title"
          style="margin-top: 20px;">
    <legend>审批流程页</legend>
</fieldset>

<form id="userForm" class="layui-form" action="" method="POST">


    <div class="layui-form-item" style="margin-left:20px;">
        <div class="layui-inline">
            <label class="layui-form-label">
                发起人
            </label>
            <div class="layui-input-block" style="width:190px;">
                <input type="text" id="initiatorName"
                       name="initiatorName" autocomplete="off"
                       readonly value="${reim.initiatorName}"
                       class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item" style="margin-left:20px;">
        <div class="layui-inline">
            <label class="layui-form-label">
                标题
            </label>
            <div class="layui-input-block" style="width:190px;">
                <input type="text" id="title"
                       name="title" autocomplete="off"
                       readonly value="${reim.title}"
                       class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item" style="margin-left:20px;">
        <div class="layui-inline">
            <label class="layui-form-label">
                报销金额
            </label>
            <div class="layui-input-block" style="width:190px;">
                <input type="text" id="price"
                       name="price" autocomplete="off"
                       readonly value="${reim.price}"
                       class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item" style="margin-left:20px;">
        <div class="layui-inline">
            <label class="layui-form-label">
                报销原因
            </label>
            <div class="layui-input-block" style="width:190px;">
                <input type="text" id="reason"
                       name="reason" autocomplete="off"
                       readonly value="${reim.reason}"
                       class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item" style="margin-left:20px;">
        <div class="layui-inline">
            <label class="layui-form-label">
                拒绝原因
            </label>
            <div class="layui-input-block" style="width:190px;">
                <input type="text" id="refuseReason"
                       name="refuseReason" autocomplete="off"
                       placeholder="请输入原因"
                       class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item" style="margin-left:20px;">
        <div class="layui-inline">
            <label class="layui-form-label">
                TaskId
            </label>
            <div class="layui-input-block" style="width:190px;">
                <input type="text" id="taskId"
                       name="taskId" autocomplete="off"
                       readonly value="${reim.taskId}"
                       class="layui-input">
            </div>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn"
                    onclick="apprReim('true');">同意申请
            </button>

            <button type="button" class="layui-btn"
                    onclick="apprReim('false');">拒绝申请
            </button>
        </div>
    </div>
</form>

<script>
    layui.use(
        ['form', 'layedit', 'laydate'],
        function () {
            var form = layui.form;
            var layer = layui.layer;
        }
    );

    function reloadPage() {
        window.location = "${ctxPath}/Reim/waitMyApprove";
    }

    function apprReim( _flag ){
        let _taskId = $("#taskId").val();
        //{1}当前用户的部门 Id
        let _deptId = '${user.dept.id}';
        //{2}拒绝原因
        let _reason = $("#refuseReason").val();
        //{3}提交地址
        $.ajax(
            {
                url:'${ctxPath}/Reim/doApprove',
                type:'post',
                data:{
                    deptId:_deptId,
                    appFlag:_flag,
                    refuseReason:_reason,
                    taskId:_taskId
                },
                dataType:"json",
                success:function( json ){
                    console.log( json );
                    let ret = json['result'];
                    if( ret==='success' ){
                        layer.msg('提交审批成功。');
                        setTimeout(reloadPage, 2000);
                    }else{
                        let cause = json['cause'];
                        layer.msg('提交审批失败, 原因:'+ cause);
                    }
                }
            }
        );
    }
</script>
</body>
</html>


